package com.springday2mybatis.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MybatisConfig {
    @Bean
    public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) {
        SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();

//        设置模型类的别名扫描，替代<typeAliases></typeAliases>标签
        ssfb.setTypeAliasesPackage("com.springday2mybatis.domain");

//        设置数据源
        ssfb.setDataSource(dataSource);
        return ssfb;
    }

//    用于替代<mappers></mappers>标签
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer() {
        MapperScannerConfigurer msc = new MapperScannerConfigurer();

        msc.setBasePackage("com.springday2mybatis.dao");

        return msc;
    }
}
